﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using DAL.Entities;

namespace DAL.EntitesDAL
{
    public class DaylopDAL : BaseDAL, UTL.IBaseDAL
    {
        #region Implement

        public int Count()
        {
            throw new NotImplementedException();
        }

        public DataTable Select()
        {
            return ExecuteQuery("sp_SelectAll_Daylop");
        }

        public DataTable Select(object obj)
        {
            throw new NotImplementedException();
        }

        public object GetByKey(object key)
        {
            throw new NotImplementedException();
        }

        public bool Delete(string id)
        {
            throw new NotImplementedException();
        }

        public bool Delete(string id1, string id2)
        {
            var sql = "sp_Delete_Daylop '{0}', '{1}'";
            sql = string.Format(sql, id1, id2);
            return ExecuteNonQuery(sql) > 0 ? true : false;
        }

        public bool Insert(object obj)
        {
            var o = (Daylop)obj;
            var sql = "set dateformat dmy; execute sp_Insert_Daylop '{0}', '{1}', N'{2}' ";
            sql = string.Format(sql, o.MaGVID, o.MalopID, o.Dayphan);
            return ExecuteNonQuery(sql) > 0 ? true : false;
        }

        public bool Update(object obj)
        {
            var o = (Daylop)obj;
            var sql = "set dateformat dmy; execute sp_Update_Daylop '{0}', '{1}', N'{2}' ";
            sql = string.Format(sql, o.MaGVID, o.MalopID, o.Dayphan);
            return ExecuteNonQuery(sql) > 0 ? true : false;
        }

        public DataTable Search(string name)
        {
            throw new NotImplementedException();
        }

        public DataTable Search(DAL.Entities.Daylop o)
        {
            string sql;

            if (o.MaGVID != "")
                sql = @"Select b.MaGV,b.Hoten as HotenDL,c.Malop,c.Tenlop as TenlopDL,a.MaGVID,a.MalopID,a.Dayphan from tb_Daylop a join tb_Giaovien b on a.MaGVID=b.MaGV join tb_Lophoc c on a.MalopID=c.Malop Where MaGVID like '%" + o.MaGVID + "%' and MalopID like '%" + o.MalopID + "%' and Dayphan like N'%" + o.Dayphan + "%'   ";
            else
                sql = @"Select b.MaGV,b.Hoten as HotenDL,c.Malop,c.Tenlop as TenlopDL,a.MaGVID,a.MalopID,a.Dayphan from tb_Daylop a join tb_Giaovien b on a.MaGVID=b.MaGV join tb_Lophoc c on a.MalopID=c.Malop Where MalopID like '%" + o.MalopID + "%' and Dayphan like N'%" + o.Dayphan + "%'   ";

            return ExecuteQuery(sql);
        }

       
        #endregion
    }
}
